package service

import (
	dom "a-common/domain"
	"a-common/utils/excel"
	"a-payment/dao"
	"a-payment/domain/entity"
	"sync"

	"github.com/xuri/excelize/v2"
)

var (
	payRecordServiceTemp *PayRecordService
	payRecordServiceOnce sync.Once
	payRecordDao         = dao.NewPayRecordDao()
)

type PayRecordService struct{}

func NewPayRecordService() *PayRecordService {
	payRecordServiceOnce.Do(func() {
		payRecordServiceTemp = &PayRecordService{}
	})
	return payRecordServiceTemp
}

// List 列表
func (m *PayRecordService) List(args *entity.PayRecordDto) (dom.PageVo, error) {
	return payRecordDao.List(args, false)
}

// Get 查
func (m *PayRecordService) Get(id string) (entity.PayRecordVo, error) {
	return payRecordDao.Get(id)
}

// Del 删
func (m *PayRecordService) Del(ids string) (int64, error) {
	return payRecordDao.Del(ids)
}

// Add 增
func (m *PayRecordService) Add(args *entity.PayRecordDto) (int64, error) {
	return payRecordDao.Add(args)
}

// Edit 改
func (m *PayRecordService) Edit(args *entity.PayRecordDto) (int64, error) {
	return payRecordDao.Edit(args)
}

// Export 导出
func (m *PayRecordService) Export(args *entity.PayRecordDto) (*excelize.File, error) {
	pageVo, err := payRecordDao.List(args, true)
	if err != nil {
		return nil, err
	}
	return excel.NormalDynamicExport(pageVo.Rows, "Sheet1", "支付记录表", "", true, false, map[string]string{})
}
